﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KPIS.GERP.WEB.GIMS.Filters;
using WebMatrix.WebData;

namespace KPIS.GERP.WEB.GIMS.Classes
{
    [InitializeSimpleMembership]
    public static class GERPMembership
    {
        public static bool Login(string userName, string password, bool persistCookie = false)
        {
            return WebSecurity.Login(userName, password, persistCookie: persistCookie);
        }

        public static void Logout()
        {
            WebSecurity.Logout();
        }

        public static string CreateAccount(string userName, string password, object propertyValues = null, bool requireConfirmationToken = false)
        {
            return WebSecurity.CreateUserAndAccount(userName, password, propertyValues, requireConfirmationToken);
        }

        public static string CreateAccount(string userName, string password, bool requireConfirmationToken = false)
        {
            return WebSecurity.CreateAccount(userName, password, requireConfirmationToken);
        }

        public static bool ChangePassword(string userName, string password, string newPassword)
        {
            return WebSecurity.ChangePassword(userName, password, newPassword);
        }

        public static bool ConfirmAccount(string accountConfirmationToken)
        {
            return WebSecurity.ConfirmAccount(accountConfirmationToken);
        }

        public static int CurrentUserId
        {
            get { return WebSecurity.CurrentUserId; }
        }

        public static string CurrentUsername
        {
            get { return WebSecurity.CurrentUserName; }
        }

        public static string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow = 1440)
        {
            return WebSecurity.GeneratePasswordResetToken(userName, tokenExpirationInMinutesFromNow);
        }

        public static DateTime GetCreateDate(string userName)
        {
            return WebSecurity.GetCreateDate(userName);
        }

        public static DateTime GetLastPasswordFailureDate(string userName)
        {
            return WebSecurity.GetLastPasswordFailureDate(userName);
        }

        public static DateTime GetPasswordChangedDate(string userName)
        {
            return WebSecurity.GetPasswordChangedDate(userName);
        }

        public static int GetPasswordFailuresSinceLastSuccess(string userName)
        {
            return WebSecurity.GetPasswordFailuresSinceLastSuccess(userName);
        }
        
        public static int GetUserId(string userName)
        {
            return WebSecurity.GetUserId(userName);
        }

        public static int GetUserIdFromPasswordResetToken(string token)
        {
            return WebSecurity.GetUserIdFromPasswordResetToken(token);
        }

        public static bool HasUserId 
        {
            get { return WebSecurity.HasUserId; }
        }

        public static bool IsAccountLockedOut(string userName, int allowedPasswordAttempts, int intervalInSeconds)
        {
            return WebSecurity.IsAccountLockedOut(userName,allowedPasswordAttempts, intervalInSeconds); 
        }

        

        public static bool IsAuthenticated
        {
            get { return WebSecurity.IsAuthenticated; }
        }
         
    }
}